package services;

import domain.entities.TranslatorDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class TranslatorsCRUDService<Traductor> implements CRUDService<Traductor>{

    private TranslatorDAO translatorDAO;
    private AddressService addressService;

    public TranslatorsCRUDService() {
    }

    @Autowired
    public TranslatorsCRUDService(TranslatorDAO translatorDAO, AddressService addressService) {
        this.translatorDAO = translatorDAO;
        this.addressService = addressService;
    }

    @Override
    public <V extends Criteria> List<Traductor> list(V criteria) {
        List<Traductor> list = translatorDAO.findAll();
        Iterator<Traductor> it = list.iterator();
        while(it.hasNext()){
            if(!criteria.isIn(it.next())){
                it.remove();
            }
        }
        return list;
    }

    public void save(Traductor traductor){
        translatorDAO.attachDirty((domain.entities.Traductor) traductor);
    }

    public domain.entities.Traductor findById(int id){
        return translatorDAO.findById(id);
    }

    public void delete(Traductor traductor){
        translatorDAO.delete((domain.entities.Traductor) traductor);
    }

    public List<Traductor> findAll(){
        return translatorDAO.findAll();
    }

    public List<Traductor> findName(String name){
        return translatorDAO.findByName(name);
    }
}
